/***************************************************************************

	Replication of descriptive information and regression of article

****************************************************************************/

log using replication_jei.log, replace 

use replication, clear 
set scheme plotplain 

/*
	Replicate Figure: check code with preserve restore  
*/ 


preserve 

collapse (mean) meanhigh = euhigh, by(year) 

tsline meanhigh if year>=1960, ///
	xlabel(1960(10)2010, grid) xtick(1960(5)2010, grid) xtitle("Year") ///
	ylabel(0(.1).6) ytick(0(.5).6, grid) /// 
	ytitle("Proportion of IOs with EU access") ///
	aspectratio(1) saving(shares.gph, replace)
	
gr export shares.png, replace

restore 

/*
	Replicate Table 1 (Logistic regression estimates)
*/

* Baseline 
quietly eststo euhigh1: logit euhigh l.nauth10 region d.iocount i.ia, cluster(iocode)

* Time 
quietly eststo cloglogHigh: cloglog euhigh l.nauth10 region d.iocount t t2 t3 i.ia, cluster(iocode)
*gen sample = e(sample)

* IO fixed effects 
quietly eststo euhighFE: xtlogit euhigh l.nauth10 d.iocount if sample, fe

* With entropy balancing weights 
quietly ebalance binauth liocount lscope pop lpop issue1 issue2 issue3 issue4 region, 
quietly eststo euhigh_ebal: logit euhigh l.binauth [pw = _webal] if sample, cluster(iocode)


esttab euhigh1 cloglogHigh euhighFE euhigh_ebal, ///
	b(3) t(2)  ///
	rename(L.binauth10 L.nauth10) keep(L.nauth10 _cons) ///
	coeflabel(L.nauth10 "Lagged IO authority" _cons "Constant") ///
	mtitles("Base" "Time" "FE" "EB") varwidth(20) modelwidth(15) ///
	stats(ll bic N, fmt(2 2 0)) star(* 0.05) ///
	note("Logit models. Clustered robust SEs. T-values in parentheses.")


/*
	Replicate Figure 2 (Predicted probability)
*/

est restore euhigh1 

margins, dydx(l.nauth10)
margins, at((p25) l.nauth10) at((p50) l.nauth10) at((p75) l.nauth10) at((p95) l.nauth10)

marginsplot, recast(line) recastci(rarea) ciopt(color(gs14)) xdimension(, labels("25{sup:th} pct" ///
"50{sup:th} pct" "75{sup:th} pct" "95{sup:th} pct")) xtitle("Authority{sub:t-1}") ytitle("Predicted probability") aspectratio(1) ytick(0(.1).8) title("") saving(pPparticipation.gph, replace)

gr export figure2.pdf, replace 

log close 
